package com.zd.lib.demo;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;

import com.zd.lib.R;
import com.zd.lib.http.response.BaseEntity;
import com.zd.lib.http.retrofit.BaseSubscriber;
import com.zd.lib.http.retrofit.RetrofitUtils;
import com.zd.lib.http.retrofit.RetrofitWrapper;
import com.zd.lib.utils.KeyboardUtils;

import java.lang.reflect.Proxy;
import java.util.List;

import rx.Subscriber;

import static com.zd.lib.http.retrofit.RetrofitUtils.wrapperRetrofit2;

public class MainActivity extends AppCompatActivity {

    private FloatingActionButton fab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        KeyboardUtils.with(this).setShowHideListener(new KeyboardUtils.SoftShowHideListener() {
            @Override
            public void softStatue(boolean isShow) {
                Log.e("zoudong", "softStatue: "+isShow);
            }
        });
        Interfaseimpl interfaseimpl = new Interfaseimpl();
        interfase o = (interfase) Proxy.newProxyInstance(Interfaseimpl.class.getClassLoader(),Interfaseimpl.class.getInterfaces(), new RetrofitWrapper(interfaseimpl));
        o.send("slkjgalgj");
        Api api = RetrofitUtils.SIGNLE().build(Api.baseUrl).create(Api.class);
        api.visitor("1", "2").compose(RetrofitUtils.<List<ListEntity>>wrapperRetrofit2()).subscribe(new BaseSubscriber<List<ListEntity>>() {
            @Override
            public void onFailure(int code, String msg) {
                Log.e("zoudong", "onFailure====" + "code = [" + code + "], msg = [" + msg + "]");
            }

            @Override
            public void onSuccess(List<ListEntity> listEntities) {
                Log.e("zoudong", "onSuccess====" + "listEntities = [" + listEntities + "]");
            }
        });

        api.visitor1("1", "2").compose(RetrofitUtils.<ListEntity>wrapperRetrofit2()).subscribe(new BaseSubscriber<ListEntity>() {
            @Override
            public void onFailure(int code, String msg) {
                Log.e("zoudong", "onFailure1====" + "code = [" + code + "], msg = [" + msg + "]");
            }

            @Override
            public void onSuccess(ListEntity listEntities) {
                Log.e("zoudong", "onSuccess1====" + "listEntities = [" + listEntities + "]");
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
